********************************************************************************
* BACKGROUND
********************************************************************************
/*	This code runs a set of robustness checks for a study analyzing
	whether the COVID-19 pandemic influenced removal decisions in U.S. 
	immigration court proceedings, particularly for Chinese nationals. 
	It begins by loading the analysis dataset and checking for parallel 
	pre-trends in removal rates between Chinese and non-Chinese respondents. It 
	then runs a placebo test to confirm that core variables (like the pandemic
	indicator) do not predict judge characteristics that should be unaffected,
	such as state-bar membership. The file proceeds with multiple 
	robustness checks: (1) varying the number of months before and after the
	pandemic start date (March 1, 2020); (2) changing the pandemic’s start
	date using alternative historical benchmarks; (3) modifying the regression
	model to include additional interaction terms, such as those between the
	pandemic period and attorney representation, court location, or case backlog
	timing. It also includes a placebo analysis using a false pandemic start 
	date to ensure that results are not spurious. Further robustness checks 
	vary the measurement window for court diversity composition and examine 
	differences across federal judicial circuits. The code also explores 
	whether changes in detention rates or case composition among detained 
	respondents could explain the main results.*/

********************************************************************************
* READ IN DATA 
******************************************************************************** 	

use pandemic_robustness_data, clear 
cd "output\robustness_checks"
			
********************************************************************************
* PARALLEL TRENDS
********************************************************************************

log using pan_parallel_trends.log, replace  

	sum p_comp_month if pandemic_MAR1==1 //722 = MARCH 2020
	reg removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.p_comp_month##i.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, robust

log close //no differences pre 722

*******************************************************************************
* PLACEBO: IJ CHARACTERISTIC AS OUTCOME 
********************************************************************************		

/*	Given that IJs’ state-bar membership should not correlate with our
	key variables of interest, we examined whether our models predicted 
	IJs’ state-bar membership in the southern United States*/

log using pandemic_outcome_placebo.log, replace 
	
	reg ever_south_reg ///
		atty i.lang i.custody_n ///
		cube_rt_caseload ///
		i.pandemic_MAR1##i.Chinese ///
		i.circuit_n ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, robust

log close 

********************************************************************************
* DIFFERENT # of months before and after March 1 start date 
********************************************************************************

/*	We treat the five months before and after March 1, 2020 as the relevant 
	time period for our pandemic analysis for the following reason: Previous
	research highlighting the effects of the pandemic on removal-order rates
	for Chinese nationals showed that the five months following the onset of the
	pandemic was the period in which IJs showed the highest levels of change in
	their decision-making vis-à-vis Chinese nationals (Authors' Study 2022).  
	However, to confirm that the choice of five months did not entirely drive 
	our main results, we re-estimated our models using a fewer 
	(as few as three months) and greater (as many as seven months) number
	of months before and after March 1, 2020.*/
	
	gen include_3 = p_comp_month >718 &  p_comp_month <725
	gen include_4 = p_comp_month >717 &  p_comp_month <726
	gen include_5 = p_comp_month >716 &  p_comp_month <727
	gen include_6 = p_comp_month >715 &  p_comp_month <728
	gen include_7 = p_comp_month >714 &  p_comp_month <729
	gen include_8 = p_comp_month >713 &  p_comp_month <730
	
*LOOP OVER VALUES
	forvalues i = 3/8 {
    frame copy default frame_`i'
    frame change frame_`i'
    keep if include_`i' == 1
   	
	logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, cluster(nat_fe)
	
	margins Chinese, dydx(pandemic_MAR1) post
		mlincom, clear 
  		mlincom (2)-(1), ///
		stat(est ul ll) add ///
		rowname("DD")
		gen CN_e = _mlincom[1, 1] 
		gen CN_ul = _mlincom[1, 2] 
		gen CN_ll = _mlincom[1, 3] 
		gen f_name = "include_`i'"
	
	keep CN_* f_name
	duplicates drop 
}	

*combine frames 
frame change frame_3
foreach f in frame_4 frame_5 frame_6 frame_7 frame_8 {
   fframeappend, using(`f') 
}

encode f_name, gen(order_s)
 
*define the value label
label define order_labels 1 "3 Months" ///
	2 "4 Months" ///
	3 "5 Months" ///
	4 "6 Months" ///
	5 "7 Months" ///
	6 "8 Months"

*apply the value label to the variable
label values order_s order_labels

*PLOT
	twoway (rcap CN_ul CN_ll order_s, sort) ///
	(scatter CN_e order_s, mcolor(black) ///
	msize(medium) msymbol(circle) mlabel(order_s)  mlabcolor(black) ///
	mlabposition(9) mlabangle(vertical) mlabgap(small)), ///
	ytitle("Differences in Pandemic Effects" ///
	"for Chinese vs. Non-Chinese Nationals") ///
	yscale(noline) yline(0) ///
	ylabel(, ticks tlcolor(black)) xtitle("") ///
	xlabel(.85 1 2 3 4 4.15, nolabels noticks nogmin nogmax) ///
	legend(off) plotregion(lcolor(black) ilcolor(none))	
	
	graph export ///
	pandemic_study_time_period.tif, ///
	width(3900) replace 
		
********************************************************************************
* PANDEMIC start dates 
********************************************************************************
/*	Our analysis used March 1, 2020 as the start of the pandemic for the reasons
	that we explain in the manuscript. However, given that other dates could 
	serve as reasonable points to mark the start of the pandemic, we tested the 
	robustness of our results using a number of different start dates for the 
	pandemic, ranging from January 31, 2020 (when the Trump administration first 
	issued travel restrictions related to the pandemic) to March 19, 2020 
	(when California became the first state to issue a stay-at-home order).*/

frame change default 
*make indicator that decision is post Trump chinese travel ban 		
	gen pandemic_JAN31 = p_comp_date > date("20200131","YMD")
*make indicator that decision is post WHO declaration 	
	gen pandemic_MAR11 = p_comp_date > date("20200311","YMD")	
*make indicator that decision is post Trump declaration of state of emergency
*https://trumpwhitehouse.archives.gov/presidential-actions/proclamation-declaring-national-emergency-concerning-novel-coronavirus-disease-covid-19-outbreak/
	gen pandemic_MAR13 = p_comp_date > date("20200313","YMD")			
*Trump's racist tweet on march 16
*https://www.ucsf.edu/news/2021/03/420081/trumps-chinese-virus-tweet-linked-rise-anti-asian-hashtags-twitter
	gen pandemic_MAR16 = p_comp_date > date("20200316","YMD")		
*California issues stay-at-home order
	gen pandemic_MAR19 = p_comp_date > date("20200319","YMD")			

*measure how many days to/from different dates 
	gen days_from_JAN31 = p_comp_date-date("20200131","YMD")
	gen days_from_MAR1 = p_comp_date-date("20200301","YMD")
	gen days_from_MAR11 = p_comp_date-date("20200311","YMD")
	gen days_from_MAR13 = p_comp_date-date("20200313","YMD")
	gen days_from_MAR16 = p_comp_date-date("20200316","YMD")
	gen days_from_MAR19 = p_comp_date-date("20200319","YMD")
	
*LOOP OVER VALUES
local list "JAN31 MAR1 MAR11 MAR13 MAR16 MAR19"  
foreach val in `list' {
     
	 frame copy default frame_`val'
	 frame change frame_`val'
	 keep if days_from_`val'<151 & days_from_`val' > -151 
	 replace pandemic_MAR1 = pandemic_`val'
	 
	 logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, cluster(nat_fe)
	
	margins Chinese, dydx(pandemic_MAR1) post
		mlincom, clear 
  		mlincom (2)-(1), ///
		stat(est ul ll ) add ///
		rowname("DD")
		gen CN_e = _mlincom[1, 1] 
		gen CN_ul = _mlincom[1, 2] 
		gen CN_ll = _mlincom[1, 3] 
		gen f_name = "`val'"
	
	keep CN_* f_name
	duplicates drop 
}

*combine frames 
frame change frame_JAN31
foreach f in  frame_MAR1 frame_MAR11 frame_MAR13 ///
	frame_MAR16 frame_MAR19 {
	fframeappend, using(`f') 
}

encode f_name, gen(order_s)

*define the value label
label define order_labels 1 "Jan. 31" ///
	2 "Mar. 1" ///
	3 "Mar. 11" ///
	4 "Mar. 13" ///
	5 "Mar. 16" ///
	6 "Mar. 19"

*apply the value label to the variable
label values order_s order_labels
		
*PLOT
	twoway (rcap CN_ul CN_ll order_s, sort) ///
	(scatter CN_e order_s, mcolor(black) ///
	msize(medium) msymbol(circle) mlabel(order_s)  mlabcolor(black) ///
	mlabposition(9) mlabangle(vertical) mlabgap(small)), ///
	ytitle("Differences in Pandemic Effects" ///
	"for Chinese vs. Non-Chinese Nationals") ///
	yscale(noline) yline(0) ///
	ylabel(, ticks tlcolor(black)) xtitle("") ///
	xlabel(.85 1 2 3 4 4.15, nolabels noticks nogmin nogmax) ///
	legend(off) plotregion(lcolor(black) ilcolor(none))	
	
	graph export ///
	pandemic_rc_start_date.tif, ///
	width(3900) replace 
		
********************************************************************************		
* Changes Affecting Chinese Nationals
********************************************************************************
/*	Many changes occurred in immigration court hearings with the start of the
	pandemic. Certain changes are likely to have affected all noncitizens in 
	removal proceedings. In mid-March 2020, for example, the EOIR temporarily
	halted hearings for all non-detained individuals until June 2020 
	(U.S. GAO 2021). The changes of most concern to this study, however, 
	are those that would have affected Chinese nationals disproportionately 
	so as to confound our key findings. We thus first tested whether the
	interaction of Chinese nationality with the pandemic period was 
	significantly correlated with observed covariates (namely, the following set
	of variables from Appendix Table 1: IJ Characteristics, Court 
	Characteristics, and Control Variables). The interaction term and its main
	effects were largely uncorrelated with these variables. But we did find
	evidence that Chinese nationals became less likely (by about 8 percent points)
	to have legal representation during the pandemic. Accordingly, we 
	re-estimated our models with an additional interaction term between the 
	pandemic period and the indicator for legal representation.  
	
	Observers have also noted considerable heterogeneity in the response of
	individual immigration courts to the pandemic. Guidelines and practices for
	masking, social distancing, and virtual hearings varied from court to court
	(id.). Some courts returned to in-person hearings for non-detained citizens
	within a couple of months, while others had not done so a year after the
	pandemic’s start (id.). These differences could confound our main results
	insofar as, for example, Chinese nationals may have been more likely to 
	appear in courts with practices responsive to the pandemic that made removal
	more probable.  We thus re-estimated our models that included an interaction
	term between court location and the pandemic period.  
	
	Finally, when the border closed with the pandemic, the EOIR turned to 
	addressing the case backlog, which grew quickly during the early days of 
	the pandemic (TRAC 2020). One might worry that our results are driven in
	part by idiosyncrasies of the courts to which backlogged cases were funneled
	or qualities of the backlogged cases. We examined the distribution of 
	proceedings by nationality over time, which indicated that no substantial 
	funneling of proceedings involving Chinese nationals to specific court 
	locations took place at the onset of the pandemic. But to further address
	the possibility of the funneling of backlogged cases to specific courts, 
	we re-estimated our models that included a three-way interaction term 
	between (1) the pandemic period, (2) the amount of time a given proceeding
	had been on the docket (i.e., the difference between filing and completion 
	dates, which could capture the extent to which a case is backlogged), and 
	(3) the court location for a given case.*/
	
	
*(1)models with an additional interaction term between the
*pandemic period and the indicator for legal representation
	
	frame copy default pand_atty_int
	frame change pand_atty_int 
	logit removal_decision ///
		i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		i.pandemic_MAR1##i.atty ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, cluster(nat_fe)
	
	margins Chinese, dydx(pandemic_MAR1) post
		mlincom, clear 
  		mlincom (2)-(1), ///
		stat(est ul ll ) add ///
		rowname("DD")
		gen CN_e = _mlincom[1, 1] 
		gen CN_ul = _mlincom[1, 2] 
		gen CN_ll = _mlincom[1, 3] 
		gen f_name = "pand_atty_int"
	
	keep CN_* f_name
	duplicates drop 
		
*(2)interaction term between court location and the pandemic period
	
	frame copy default pand_court
	frame change pand_court 
		
*use linear prob and omit base_n 24 -- can't get convergence otherwise
	
	reg removal_decision ///
		i.lang i.custody_n  atty ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.Chinese ///
		i.pandemic_MAR1 ///
		i.pandemic_MAR1#i.Chinese  ///
		i.base_n ////
		i.pandemic_MAR1#i.base_n ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 &base_n!=24, cluster(nat_fe)
	
	margins Chinese, dydx(pandemic_MAR1) post
		mlincom, clear 
  		mlincom (2)-(1), ///
		stat(est ul ll) add ///
		rowname("DD")
		gen CN_e = _mlincom[1, 1] 
		gen CN_ul = _mlincom[1, 2] 
		gen CN_ll = _mlincom[1, 3] 
		gen f_name = "pand_court"
		keep CN_* f_name
		duplicates drop 
		
*(3) interaction term btw: (1) the pandemic period, 
*(2) the amount of time a given case had been on the docket
*(i.e., the difference between filing and completion dates,
*which could capture the extent to which a case is
*backlogged), and (3) the court location for a given case.
			
	frame copy default pan_comp_court
	frame change pan_comp_court

*merge filing date information 
	merge 1:1 idnproceeding using input_date.dta
	fre _m  if include_m==1 &is_missing==0 & ///
	IJ_pre_post_pan==1
	keep if _m==3

*make indicator of time to decision 
	gen time_to_decision = p_comp_date-input_date  	

*have to use linear prob and omit base_n 24 -- can't get estimates otherwise
	
	reg removal_decision ///
		i.lang i.custody_n atty ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.Chinese ///
		i.pandemic_MAR1#i.Chinese  ///
		i.base_n##c.time_to_decision##i.pandemic_MAR1 ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 &base_n!=24, cluster(nat_fe)
	
	margins Chinese, dydx(pandemic_MAR1) post
		mlincom, clear 
  		mlincom (2)-(1), ///
		stat(est ul ll ) add ///
		rowname("DD")
		gen CN_e = _mlincom[1, 1] 
		gen CN_ul = _mlincom[1, 2] 
		gen CN_ll = _mlincom[1, 3] 
		gen f_name = "pan_comp_court"
		
	keep CN_* f_name
	duplicates drop 
			
 foreach f in  pand_atty_int  pand_court frame_MAR1 {
   fframeappend, using(`f') 
}

	replace f_name = "1" if f_name=="MAR1"
	replace f_name = "2" if f_name=="pand_atty_int"
	replace f_name = "3" if f_name=="pand_court"
	replace f_name = "4" if f_name=="pan_comp_court"

	encode f_name, gen(order_s)
 
*define the value label
label define order_labels 1 "Full Model" ///
	2 "Full Model + Attorney*Pandemic Interaction" ///
	3 "Full Model + Court*Pandemic Interaction" ///
	4 "Full Model + Court*Time to decision*Pandemic Interaction" ///
                      

*apply the value label to the variable
label values order_s order_labels
		
*PLOT
	twoway (rcap CN_ul CN_ll order_s, sort) ///
	(scatter CN_e order_s, mcolor(black) ///
	msize(medium) msymbol(circle) mlabel(order_s)  mlabcolor(black) ///
	mlabposition(11) mlabangle(vertical) mlabgap(small)), ///
	ytitle("Differences in Pandemic Effects" ///
	"for Chinese vs. Non-Chinese Nationals") ///
	yscale(noline) yline(0) ///
	ylabel(-0.1(.05).2, ticks tlcolor(black)) xtitle("") ///
	xlabel(.85 1 2 3 4 4.15, nolabels noticks nogmin nogmax) ///
	legend(off) plotregion(lcolor(black) ilcolor(none))	
	
	graph export ///
	pandemic_rc_changes_affecting_CN.tif, ///
	width(3900) replace 
				
*******************************************************************************
* PLACEBO: FALSE START DATE 
********************************************************************************
/* 	We constrained our analysis to the pre-pandemic period and assigned January 1,
	2020 as a “false” or placebo pandemic start period. We then estimated a 
	treatment effect for the false pandemic period that we allowed to interact 
	with the indicator for whether the proceeding pertained to a Chinese national.*/
	
	frame copy default frame_placebo 
	frame change frame_placebo
	sum p_comp_month if pandemic_MAR1==0 & include_m==1 //719 is the midpoint 
	gen false_pandemic_treatment=p_comp_month>718
    
foreach var in ij_asian hispanic_ijfemale {
	
	logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.false_pandemic_treatment##i.Chinese ///
		1.`var'#1.Chinese ///
		1.`var'#1.false_pandemic_treatment ///
		1.false_pandemic_treatment#1.`var'#1.Chinese ///
		1.apt_dem_pres#1.Chinese ///
		1.apt_dem_pres#1.false_pandemic_treatment ///
		1.false_pandemic_treatment#1.apt_dem_pres#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & pandemic_MAR1==0, cluster(IJ_FE_ID)
	
	margins `var'#Chinese, dydx(false_pandemic_treatment) post
		mlincom, clear 
  		mlincom (4-2)-(3-1), ///
		stat(est ul ll ) add ///
		rowname("DD")
		gen `var'_e = _mlincom[1, 1] 
		gen `var'_ul = _mlincom[1, 2] 
		gen `var'_ll = _mlincom[1, 3] 
}

*CONTINUOUS CHARACTERISTICS 		

foreach var in  percent_asian_14 percent_hispanic_14 {
	
	logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		c.`var'##i.false_pandemic_treatment##i.Chinese ///
		1.apt_dem_pres#1.Chinese ///
		1.apt_dem_pres#1.false_pandemic_treatment ///
		1.false_pandemic_treatment#1.apt_dem_pres#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White" ///
		& pandemic_MAR1==0, cluster(IJ_FE_ID)

	sum `var' if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White", d
		local median_val = `r(p50)'
		local SD = `r(sd)'
		local median_SD = `median_val' + `SD'
	
	margins Chinese, dydx(false_pandemic_treatment) ///
		at(`var'= (`median_val' `median_SD')) post 
		mlincom, clear 
  		mlincom (4-2)-(3-1), ///
		stat(est ul ll) add ///
		rowname("DD")
	
	gen `var'_e = _mlincom[1, 1] 
	gen `var'_ul = _mlincom[1, 2] 
	gen `var'_ll = _mlincom[1, 3] 
}	

foreach var in  percent_female_14 {
	
	logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		c.`var'##i.false_pandemic_treatment##i.Chinese ///
		1.apt_dem_pres#1.Chinese ///
		1.apt_dem_pres#1.false_pandemic_treatment ///
		1.false_pandemic_treatment#1.apt_dem_pres#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & female==0 ///
		& pandemic_MAR1==0, cluster(IJ_FE_ID)

	sum `var' if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & female==0, d
		local median_val = `r(p50)'
		local SD = `r(sd)'
		local median_SD = `median_val' + `SD'
	
	margins Chinese, dydx(false_pandemic_treatment) ///
		at(`var'= (`median_val' `median_SD')) post 
		mlincom, clear 
  		mlincom (4-2)-(3-1), ///
		stat(est ul ll) add ///
		rowname("DD")
	
	gen `var'_e = _mlincom[1, 1] 
	gen `var'_ul = _mlincom[1, 2] 
	gen `var'_ll = _mlincom[1, 3] 
}	
		
*store output from margins 
	
	keep ij_asian_ll hispanic_ij_ll female_ll ///
		percent_asian_14_ll percent_hispanic_14_ll percent_female_14_ll ///
		ij_asian_ul hispanic_ij_ul female_ul  ///
		percent_asian_14_ul percent_hispanic_14_ul percent_female_14_ul ///
		ij_asian_e hispanic_ij_e  female_e ///
		percent_asian_14_e percent_hispanic_14_e percent_female_14_e

	
	duplicates drop 
	xpose, clear varname 
	rename (v1) (Pan_effect)
	generate str var_id = substr( _varname , 1, strlen( _varname) - 2)
	gen yes_no=substr(_varname,-2,.) 
	
	replace var_id ="6. Percent Female Court" if strpos( var_id, "percent_female")
	replace var_id ="5. Percent Hisp Court" if strpos( var_id, "percent_hispan")
	replace var_id ="3. Female" if strpos(var_id, "female")
	replace var_id ="1. Asian" if strpos( var_id, "ij_asian")
	replace var_id ="2. Hispanic" if strpos( var_id, "hispanic_ij")
	replace var_id ="4. Percent Asian Court" if strpos( var_id, "percent_asian")
	
	gen dif = Pan_effect if yes_no=="_e"
	gen ul = Pan_effect if yes_no=="ul"
	gen ll = Pan_effect if yes_no=="ll"
   
   
	bysort var_id : egen Difference = max(dif)
	bysort var_id : egen U_CI = max(ul)   
	bysort var_id : egen L_CI = max(ll)   
	keep var_id  Difference U_CI L_CI
	duplicates drop 
   
	encode var_id, gen(var_idn)
	
	label define graph_ab_difn  ///
	1 "Asian" ///
	2 "Hispanic" ///
	3 "Female" ///
	4  "Percent Asian Court +SD" ///
	5  "Percent Hispanic Court +SD" ///
	6 "Percent Female Court +SD" 
	
	label values var_idn graph_ab_difn
	
	gen f_name = "placebo"
   
   *ACTUAL FIGURE
	twoway (rcap U_CI L_CI var_idn) ///
	(scatter Difference var_idn, mcolor(black) ///
	msymbol(circle) mlabel(var_idn) ///
	mlabcolor(black) mlabposition(6) ///
	mlabangle(vertical)), ///
	ytitle("Differences in Placebo Pandemic Effects" ///
	"for Chinese vs. Non-Chinese Nationals") ///
	yline(0) xtitle("") ///
	xlabel(1(1)6.5, labels labcolor(none) noticks) ///
	legend(off)

 	graph export ///
	pandemic_placebo_effects_on_CN.tif, ///
	width(3900) replace 
			
********************************************************************************
* DIFFERENT COMPOSITION LENGTH 
********************************************************************************
/*	Our analysis uses versions of Percent Asian Court, Percent Hispanic Court,
	and Percent Female Court that correspond to a given court’s demographic 
	composition in the two weeks prior to the completion of a given proceeding.
	We re-estimated our models using an alternative set of these same measures 
	that corresponded to a given court’s demographic composition in the previous
	10 and 30 days, respectively.*/
	
	frame change default 
	
	foreach var in  percent_asian_30 percent_asian_10y {
	
	logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		c.`var' ///
		i.pandemic_MAR1##i.Chinese ///
		c.`var'#1.Chinese ///
		c.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#c.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White", cluster(nat_fe)

log using  pan_`var'.log, replace 
	
	sum `var' if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White", d
		local median_val = `r(p50)'
		local SD = `r(sd)'
		local median_SD = `median_val' + `SD'
	
	margins Chinese, dydx(pandemic_MAR1) ///
		at(`var'= (`median_val' `median_SD')) post 
		mlincom, clear 
		  mlincom (3-1), ///
		stat(est se p) add ///
		rowname("Non CN")		
		mlincom (4-2), ///
		stat(est se p) add ///
		rowname("CN")	
		mlincom (4-3),  ///
		stat(est se p) add ///
		rowname(`var'==1)		
		mlincom (2-1), ///
		stat(est se p) add ///
		rowname(`var'==0)	
  		mlincom (4-2)-(3-1), ///
		stat(est se p) add ///
		rowname("DDD")
		
log close 	
}

********************************************************************************
*CIRCUIT DIFFERENCES
********************************************************************************
/*	Geography may confound our results, as caselaw applicable to immigration
	adjudication may vary across federal judicial circuits.  
	This is relevant because the Chinese nationals are unlikely to be
	randomly or evenly distributed across these jurisdictions. Our main 
	analysis uses judge fixed effects, which largely control for jurisdiction-
	specific factors that remain constant over time. However, to more directly 
	address possible variations in laws across jurisdictions, we also re-estimated
	the models using fixed effects for federal judicial circuits.*/
 
foreach var in ij_asian {
log using pan_`var'_circuit_FE.log, replace 
	
	logit removal_decision i.circuit_n ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		1.`var'#1.Chinese ///
		1.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#1.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, cluster(nat_fe)

log close 
}

foreach var in  percent_asian_14 {
log using  pan_`var'_circuit_FE.log, replace 
	
	logit removal_decision i.circuit_n ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		c.`var' ///
		c.`var'#1.Chinese ///
		c.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#c.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1  & ij_race=="White", cluster(nat_fe)

log close 
}

********************************************************************************
* IJ WORK EXPERIENCE
********************************************************************************
/*	IJs’ pre-appointment career experiences may shape how they respond to 
 	the types of outside influences that we examine in this study. Furthermore, 
	judges who are Asian, Hispanic, female, or who preside in courts that are 
	especially diverse in terms of values for Percent Asian Court, Percent 
	Hispanic Court, or Percent Female Court, may systematically vary in their
	pre-appointment career experiences compared to their counterparts.  
	We thus re-estimated our models that includedinteraction terms between
	the Matter of A-B- and indicators for each of the following, respectively: 
	(1) whether a given IJ ever worked in an NGO setting prior to appointment, 
	and (2) whether a given IJ ever worked for the DHS (or its predecessor agency,
	Immigration and Naturalization Service) prior to appointment. */
	
foreach var in ij_asian {
log using  pan_`var'_change_ngo.log, replace 
	
	logit removal_decision ///
	atty i.lang i.custody_n  ///
	cube_rt_caseload i.IJ_FE_ID ///
	1.pandemic_MAR1#1.ever_ngo ///
	i.pandemic_MAR1##i.Chinese ///
	1.`var'#1.Chinese ///
	1.`var'#1.pandemic_MAR1 ///
	1.pandemic_MAR1#1.`var'#1.Chinese ///
	if include_m==1 &is_missing==0 & ///
	IJ_pre_post_pan==1, cluster(nat_fe)

log close 
}

foreach var in percent_asian_14 {
log using  pan_`var'_change_ngo.log, replace 

	logit removal_decision ///
		atty i.lang i.custody_n  ///
		cube_rt_caseload i.IJ_FE_ID ///
		1.pandemic_MAR1#1.ever_ngo ///
		i.pandemic_MAR1##i.Chinese ///
		c.`var' ///
		c.`var'#1.Chinese ///
		c.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#c.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White", cluster(nat_fe)

log close 
} 

foreach var in ij_asian apt_dem_pres {
log using pan_`var'_change_ngo.log, replace 
	
	logit removal_decision ///
		atty i.lang i.custody_n ///
		cube_rt_caseload i.IJ_FE_ID ///
		1.pandemic_MAR1#1.ever_ins ///
		i.pandemic_MAR1##i.Chinese  ///
		1.`var'#1.Chinese ///
		1.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#1.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1, cluster(nat_fe)

log close 
}

foreach var in percent_asian_14 {
log using  pan_`var'_change_ngo.log, replace 

	logit removal_decision ///
		atty i.lang i.custody_n  ///
		cube_rt_caseload i.IJ_FE_ID ///
		1.pandemic_MAR1#1.ever_ins ///
		i.pandemic_MAR1##i.Chinese ///
		c.`var' ///
		c.`var'#1.Chinese ///
		c.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#c.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White", cluster(nat_fe)

log close 
}

********************************************************************************
*DETAINED DOCKET
********************************************************************************
/*	We examined the possibility that there may have been an increase in 
	detained proceedings among completed proceedings post pandemic that 
	might confound the results. Most completed proceedings for Chinese 
	nationals were not detained before the pandemic: Between October 1, 
	2019 and February 29, 2020, only 14 percent were detained. But even
	during the pandemic, most completed proceedings for Chinese nationals 
	were not detained: Between March 1, 2020 and July 31, 2020, 40 percent
	were detained. This 26 percentage-point increase in the detention rate
	for Chinese nationals is comparable to what we see among the completed 
	proceedings for non-Chinese nationals. Thus, while an increased share 
	of completed proceedings for Chinese nationals were detained proceedings
	during the pandemic (and we know that detained noncitizens are likely to
	fare worse in removal proceedings), this increase by itself would not 
	explain the disproportionate increase in the removal rate of Chinese
	nationals during the pandemic. In addition, even when we limit our 
	analysis to a sample of only detained proceedings, we continue to find 
	a sizeable and significant increase in the removal rates of Chinese 
	nationals associated with the pandemic that does not occur among 
	non-Chinese nationals.*/
	
log using pan_percent_detained_cases_pre_post.log, replace 
	mean Detained if include_m==1 &is_missing==0 & ///
	IJ_pre_post_pan==1, over(pandemic_MAR1)
log close 


log using pan_percent_detained_cases_chinese_pre_post.log, replace 
	mean Detained if include_m==1 &is_missing==0 & ///
	IJ_pre_post_pan==1 &Chinese==1, over(pandemic_MAR1)
log close 

*in months leading up to pandemic, 43 percent of cases completed were detained
*in pandemic period, 69 percent of cases completed were detained.
	
foreach var in ij_asian {
	
	logit removal_decision ///
		atty i.lang ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		1.`var'#1.Chinese ///
		1.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#1.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 &custody_n==1, cluster(nat_fe)
		
log using only_det_pan_`var'.log, replace 
	
	margins `var'#Chinese, dydx(pandemic_MAR1) post
		mlincom, clear 
		mlincom (3-1), ///
		stat(est se p) add ///
		rowname("Non CN")		
		mlincom (4-2), ///
		stat(est se p) add ///
		rowname("CN")	
		mlincom (4-3), ///
		stat(est se p) add ///
		rowname(`var'==1)		
		mlincom (2-1), ///
		stat(est se p) add ///
		rowname(`var'==0)	
  		mlincom (4-2)-(3-1), ///
		stat(est se p) add ///
		rowname("DDD")

log close 			
}

foreach var in percent_asian_14 {

	logit removal_decision ///
		atty i.lang ///
		cube_rt_caseload i.IJ_FE_ID ///
		i.pandemic_MAR1##i.Chinese ///
		c.`var' ///
		c.`var'#1.Chinese ///
		c.`var'#1.pandemic_MAR1 ///
		1.pandemic_MAR1#c.`var'#1.Chinese ///
		if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 &custody_n==1 & ij_race=="White", cluster(nat_fe)

log using  only_det_pan_`var'.log, replace 
	
	sum `var' if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & ij_race=="White", d
		local median_val = `r(p50)'
		local SD = `r(sd)' //rounding to integer
		local median_SD = `median_val' + `SD'
	
	margins Chinese, dydx(pandemic_MAR1)  ///
		at(`var'= (`median_val' `median_SD')) post 
		mlincom, clear 
		mlincom (3-1), ///
		stat(est se p) add ///
		rowname("Non CN")		
		mlincom (4-2), ///
		stat(est se p) add ///
		rowname("CN")	
		mlincom (4-3), ///
		stat(est se p) add ///
		rowname(`var'==1)		
		mlincom (2-1), ///
		stat(est se p) add ///
		rowname(`var'==0)	
  		mlincom (4-2)-(3-1), ///
		stat(est se p) add ///
		rowname("DDD")

log close 
}

********************************************************************************
* GRAPH PERCENT OF NATIONALITIES DETAINED PRE-POST PANDEMIC START
********************************************************************************
/* It's possible that the pandemic triggered compositional changes in the 
	detained population itself, and that such changes may have been more 
	pronounced among detained Chinese nationals, which could confound our
	results.  One way to identify such an issue is to plot nationality 
	proportions among detained respondents over the pandemic study period.
	We have done so and compared the proportion of all detained proceedings
	by nationality before and after the pandemic. That analysis did not 
	show any notable changes in the relative share of detained proceedings 
	by nationality.  Of all detained proceedings completed between October
	1, 2019 and February 29, 2020, 1.5 percent corresponded to Chinese 
	nationals, while 1.9 percent corresponded to Chinese nationals between
	March 1, 2020 and July 31, 2020. */

	gen one_1 = include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 & ///
		pandemic_MAR1==0
	gen one_2 = include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 & ///
		pandemic_MAR1==1
	gen one_3 = include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 
		
	bysort p_nat: egen total_one_1 = total(one_1)
	bysort p_nat: egen total_one_2 = total(one_2)
	
	groups p_nat if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 ///
		& pandemic_MAR1==0, select(15) order(h)
	
	gen in_pregroup = total_one_1>143
	
	groups p_nat if include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 ///
		& pandemic_MAR1==1, select(15) order(h)		
	
	gen in_postgroup = total_one_1>87

	gen total_var = total_one_1 if in_pregroup==1 & ///
		include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 ///
		& pandemic_MAR1==0 
	
	replace total_var = total_one_2 if in_postgroup==1 & ///
		include_m==1 &is_missing==0 & ///
		IJ_pre_post_pan==1 & custody_n==1 ///
		& pandemic_MAR1==1
		
	gen new_nat_marker = p_nat
	replace new_nat_marker = "Mexico" if new_nat_marker=="mx"
	replace new_nat_marker = "Cuba" if new_nat_marker=="cu"
	replace new_nat_marker = "Guatemala" if new_nat_marker=="gt"
	replace new_nat_marker = "Honduras" if new_nat_marker=="ho"
	replace new_nat_marker = "El Salvador" if new_nat_marker=="es"
	replace new_nat_marker = "Cameroon" if new_nat_marker=="cm"
	replace new_nat_marker = "Nicaragua" if new_nat_marker=="nu"
	replace new_nat_marker = "Venezuela" if new_nat_marker=="ve"
	replace new_nat_marker = "Ecuador" if new_nat_marker=="ec"
	replace new_nat_marker = "Dom. Rep." if new_nat_marker=="dr"
	replace new_nat_marker = "China" if new_nat_marker=="ch"
	replace new_nat_marker = "India" if new_nat_marker=="in"
	replace new_nat_marker = "Brazil" if new_nat_marker=="br"
	replace new_nat_marker = "Jamaica" if new_nat_marker=="jm"
	replace new_nat_marker = "Haiti" if new_nat_marker=="ha"
	replace new_nat_marker = "Colombia" if new_nat_marker=="co"

	graph hbar (percent) one_3 if one_3==1 & !missing(total_var), ///
	over(new_nat_marker, sort(total_var) descending) ///
	nofill bar(1, fcolor(black) lcolor(black)) ///
	blabel(bar, format(%9.2g)) ///
	ytitle("Percent of Detained Population") ///
	by(, title("") subtitle("") caption("") note("")) by(pandemic_MAR1)

	graph export ///
	percent_of_detained_pop_by_pandemic_period_dif.tif, ///
	width(3900) replace 